package com.tianqu.tms.www.statistics.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsStatisticsAjaxAction;
import com.tianqu.tms.www.api.action.TmsCarGateAction;
import com.tianqu.tms.www.api.network.PSHTTPUtil;
import com.tianqu.tms.www.statistics.dto.TradeTransferDto;
import com.tianqu.tms.www.statistics.service.TradeTransferService;
/**
 * 交易过户
 * @author hejian
 *
 */
public class TradeTransferController extends TmsStatisticsAjaxAction {

	private Logger LOGGER = Logger.getLogger(TmsCarGateAction.class);
	
	// 一、累计天数 二、累计交易过户总数 & 三、累计交易过户总价
	public ActionForward getCumulativeDays(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception { 
		
		TradeTransferService tradeTransferService = new TradeTransferService();
		
		// 统计累计天数
		TradeTransferDto tradeTransferDto = tradeTransferService.getCumulativeDays();
		
		String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getCumulativeDays:"+json);
		responseValues(response, json, JSON);
		
		return null;
    }  
    
//	// 取得今天交易过户量 &今天商户交易过户量&今天社会交易过户量
//    public ActionForward getTodayTransaction(ActionMapping mapping, ActionForm form,  
//            HttpServletRequest request, HttpServletResponse response)throws Exception {  
//    	
//    	TradeTransferService tradeTransferService = new TradeTransferService();
//    	
//    	// 二、累计交易过户总数 & 三、累计交易过户总价
//    	TradeTransferDto tradeTransferDto = tradeTransferService.getTodayTransaction();
//    	
//    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
//		
//		LOGGER.debug("call getTodayTransaction:"+json);
//		responseValues(response, json, JSON);  
//		
//    	return null; 
//    }
    
    // 取得今天交易过户量 &今天商户交易过户量&今天社会交易过户量&当月新增数据 以及 当月新增同比
    public ActionForward getCurrentMonthSameRate(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	// 取得当月新增数据 以及 当月新增同比
    	TradeTransferDto tradeTransferDto = tradeTransferService.getCurrentMonthSameRate();
    	
    	//取得今天交易过户量 &今天商户交易过户量&今天社会交易过户量
    	TradeTransferDto tradeTransferTodayDto = tradeTransferService.getTodayTransaction();
    	
    	// 今天交易过户量
		tradeTransferDto.setTransferNum(tradeTransferTodayDto.getTransferNum());
		// 今天商户交易过户量
		tradeTransferDto.setTranType11(tradeTransferTodayDto.getTranType11());
		// 今天社会交易过户量
		tradeTransferDto.setTranType12(tradeTransferTodayDto.getTranType12());
		//本地过户量
		tradeTransferDto.setTranNum1(tradeTransferTodayDto.getTranNum1());
		//本地转出量
		tradeTransferDto.setTranNum2(tradeTransferTodayDto.getTranNum2());
		//外地转入量
		tradeTransferDto.setTranNum3(tradeTransferTodayDto.getTranNum3());
		//新车上牌量
		tradeTransferDto.setTranNum4(tradeTransferTodayDto.getTranNum4());
		//县区车辆量
		tradeTransferDto.setTranNum5(tradeTransferTodayDto.getTranNum5());
		// 变更业务量
		tradeTransferDto.setTranNum6(tradeTransferTodayDto.getTranNum6());
		//补牌补证补书量
		tradeTransferDto.setTranNum7(tradeTransferTodayDto.getTranNum7());
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getCurrentMonthSameRate:"+json);
		responseValues(response, json, JSON);  
		
    	return null; 
    }
    
    //  十、国产VS进口 
    public ActionForward getDomesticVSImport(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	// 取得当月新增数据 以及 当月新增同比
    	TradeTransferDto tradeTransferDto = tradeTransferService.getDomesticVSImport();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getDomesticVSImport:"+json);
		responseValues(response, json, JSON);  
		
    	return null; 
    }
    
    //  十一、个人VS企业 
    public ActionForward getPersonVSCompany(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	// 取得当月新增数据 以及 当月新增同比
    	TradeTransferDto tradeTransferDto = tradeTransferService.getPersonVSCompany();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getPersonVSCompany:"+json);
		responseValues(response, json, JSON);  
		
    	return null; 
    }
    
    //  十二、黄牌VS蓝牌
    public ActionForward getYellowVSBlue(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	// 取得当月新增数据 以及 当月新增同比
    	TradeTransferDto tradeTransferDto = tradeTransferService.getYellowVSBlue();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getYellowVSBlue:"+json);
		responseValues(response, json, JSON);  
		
    	return null; 
    }
    
    // 八、价格分布
    public ActionForward getPriceDistribute(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	// 取得当月新增数据 以及 当月新增同比
    	TradeTransferDto tradeTransferDto = tradeTransferService.getPriceDistribute();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getPriceDistribute:"+json);
		responseValues(response, json, JSON);  
		
    	return null; 
    }
    
    // 九、车龄分布
    public ActionForward getCarAgeDistribute(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	// 取得当月新增数据 以及 当月新增同比
    	TradeTransferDto tradeTransferDto = tradeTransferService.getCarAgeDistribute();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
		
		LOGGER.debug("call getCarAgeDistribute:"+json);
		responseValues(response, json, JSON);  
		
    	return null; 
    }
    
//    // 取得八、价格分布 九、车龄分布 十、国产VS进口 十一、个人VS企业十二、黄牌/蓝牌
//    public ActionForward getPriceInfo(ActionMapping mapping, ActionForm form,  
//            HttpServletRequest request, HttpServletResponse response)throws Exception {  
//    	
//    	TradeTransferService tradeTransferService = new TradeTransferService();
//    	
//    	// 取得当月新增数据 以及 当月新增同比
//    	TradeTransferDto tradeTransferDto = tradeTransferService.getPriceInfo();
//    	
//    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
//		
//		LOGGER.debug("call getPriceInfo:"+json);
//		responseValues(response, json, JSON);  
//		
//    	return null; 
//    }
    
    // 取得十三、流出省TOP5
    public ActionForward getTop5OfProv(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	TradeTransferDto tradeTransferDto = tradeTransferService.getTop5OfProv();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
    	
		LOGGER.debug("call getTop5OfProv:"+json);
		responseValues(response, json, JSON);  
    	return null; 
    }
    
    // 取得十四、流出本省城市TOP5
    public ActionForward getTop5OfCity(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	
    	TradeTransferDto tradeTransferDto = tradeTransferService.getTop5OfCity();
    	
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
    	
		LOGGER.debug("call getTop5OfCity:"+json);
		responseValues(response, json, JSON);  
    	return null; 
    }
    
    // 取得十五、最近10个月交易过户量走势图
    public ActionForward getLastTenMonthsTransferNum(ActionMapping mapping, ActionForm form,  
            HttpServletRequest request, HttpServletResponse response)throws Exception {  
    	
    	TradeTransferService tradeTransferService = new TradeTransferService();
    	TradeTransferDto tradeTransferDto = tradeTransferService.getLastTenMonthsTransferNum();
    	String json = PSHTTPUtil.convertJavaBeanToJson(tradeTransferDto);
    	
		LOGGER.debug("call getLastTenMonthsTransferNum:"+json);
		responseValues(response, json, JSON);  
    	return null; 
    }
}
